﻿using System;
using System.Speech.Synthesis;
using Bookvar.AddIns.AddInViews;
using Bookvar.Common;
using Bookvar.ObjectModel;
using System.AddIn;

namespace Bookvar.AddIns.Speech
{
    [AddIn("Bookvar Speech AddIn", Version = "1.0.0.0")]
    public class SpeechAddin: BookvarAddinView
    {
        public override void Execute(Topic topic)
        {
            if (topic == null)
            {
                return;
            }

            using ( SpeechSynthesizer synthesizer = new SpeechSynthesizer() )
            {
                SpeakRecursive( topic, synthesizer );
            }
        }

        private static void SpeakRecursive( Topic topic, SpeechSynthesizer synthesizer )
        {
            synthesizer.Speak( topic.Name );
            foreach (Topic subTopic in topic.SubTopics)
            {
                SpeakRecursive( subTopic, synthesizer );
            }
        }
        
		public override AddinInfo Info
		{
			get
			{
				AddinInfo info = new AddinInfo();
				info.Name = "Speech";
				info.Group = "Multimedia";
				info.Description = "Read out the mind map";
				info.Image = AssemblyUtility.LoadImageFromResources(
					typeof(SpeechAddin).Assembly, "Bookvar.AddIns.Speech.Speech.png");

				return info;
			}
		}
	}
}
